<template>
    <div>
        <h1>登录</h1>
        <table>
            <tbody>
                <tr>
                    <td>管理员帐号</td>
                    <td>
                        <input type="text" v-model="queryInfo.userName">
                    </td>
                </tr>

                <tr>
                    <td>管理员密码</td>
                    <td>
                        <input type="password" v-model="queryInfo.userPwd">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-info" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
import {useUserStore} from '@/stores/user'

const route=useRoute();
const router=useRouter();

const abc=useUserStore();

let queryInfo:any=reactive({
    userName:"",
    userPwd:""
})

const login=()=>{
    if(queryInfo.userName==''){
        alert('管理员账号不能为空');
        return;
    }
    if(queryInfo.userPwd==''){
        alert('管理员密码不能为空');
        return;
    }
    axios({
        url:'/api/Admin/AdminLogin',
        method:'get',
        params:queryInfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('管理员账号不存在')
        }
        if(res.data==-2){
            alert('密码错误')
        }
        else{
            alert('登录成功')
            abc.userInfo=res.data;
            router.push('/addHouse')
        }
    })
    .catch(err=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>